using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System.Collections.Generic;

namespace ADiKt {
    class SpinEntry : Entry{
        public delegate void onEvent();
        public event onEvent updateGlobal;
        public event EventHandler Next;
        public event EventHandler Last;
        
        Dictionary<object, string> options;
        List<object> values;
        int current;
        string title;
        public object value;

        public SpinEntry(string titleText, Dictionary<object, string> options, object defaultValue, onEvent globalUpdate) {
            this.options = options;
            values = new List<object>(options.Keys);
            title = titleText;
            Text = title + options[defaultValue];
            current = values.IndexOf(defaultValue);
            updateGlobal += globalUpdate;
            Next += OnNext; 
            Last += OnLast;
        }

        public SpinEntry(string fullText) {
            Text = fullText;
        }

        public void OnNext(object sender) {
            current = (current < values.Count -1) ? current+1 : current;
            value = values[current];
            this.Text = title + options[value];
        }

        public void OnLast(object sender) {
            current = current > 0 ? current - 1 : current;
            value = values[current];
            this.Text = title + options[value];
        }

        ///<summary> Method for raising the next event. </summary>
        protected internal virtual void OnNext() {
            if (Next != null)
                Next(this);
            if (updateGlobal != null)
                updateGlobal();
        }

        ///<summary> Method for raising the last event. </summary>
        protected internal virtual void OnLast() {
            if (Last != null)
                Last(this);
            if (updateGlobal != null)
                updateGlobal();
        }

    }
}